home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / libfpvm / pvmfperror.m4 < prev    next >
Text File  |  1997-07-22  |  1KB  |  45 lines

  1.  
  2. /* $Id: pvmfperror.m4,v 1.2 1996/10/04 15:27:26 pvmsrc Exp $ */
  3.  
  4. #include <stdio.h>
  5. #include "pvm3.h"
  6. #include "pvm_consts.h"
  7.  
  8. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  9.  
  10. void
  11. FUNCTION(pvmfperror) ARGS(`STRING_ARG(p), info')
  12. STRING_ARG_DECL(p);
  13.     int *info;
  14. {
  15.     static char *buf = 0;
  16.     static int buflen = 0;
  17.     char *malloc();
  18.  
  19.     /*
  20.      * Have to have a NUL at the end of the string, and
  21.      * the only way to do this portably is to copy the whole string
  22.      * into a malloc'ed buffer.  We keep the buffer around for
  23.      * future use rather than free'ing it each time we're done.
  24.      */
  25.     if (!buf)
  26.         buf = malloc(buflen = STRING_LEN(p) + 1);
  27.     else
  28.         if (STRING_LEN(p) + 1 > buflen) {
  29.             buflen = MAX(STRING_LEN(p) + 1, buflen * 2);
  30.             /* don't use realloc; it might cause old data to be copied */
  31.             free(buf);
  32.             buf = malloc(buflen);
  33.         }
  34.     if (!buf) {
  35.         fprintf(stderr, "pvmfperror PvmNoMem");
  36.         *info = PvmNoMem;
  37.         return;
  38.     }
  39.     strncpy(buf, STRING_PTR(p), STRING_LEN(p));
  40.     buf[STRING_LEN(p)] = '\0';
  41.  
  42.     *info = pvm_perror(buf);
  43. }
  44.  
  45.